<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #test{
            width: 200px;
            height: 200px;
            background-color: #afe;
        }
    </style>
</head>
<body>
    <div id="test">
        我是哈哈事件要点击的地方
    </div>

    <script>
        const div=document.getElementById('test')

        // 创建一个haha事件
        const haha=new Event('haha')

        div.addEventListener('haha',()=>{
            console.log('你笑了');
        })

        setTimeout(() => {
            div.dispatchEvent(haha)
        }, 2000);

    </script>
    
</body>
</html>